<html>

	<head>
		<meta charset="UTF-8">
		<title>新增用户</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style>
			.layui-form {
				width: 35%;
			}
			
			.layui-input {
				width: 100% !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">

				<!--标题栏-->
				<p class="content_title">用户管理 &nbsp;&nbsp;>&nbsp;&nbsp;新增用户</p>
				<!--标题栏-->

				<form class="layui-form mt20">
					<div class="layui-form-item">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-block">
							<input type="text" name="userAccount" lay-verify="required" autocomplete="off" placeholder="请输入用户名" class="layui-input w30">
						</div>
					</div>
					<!--<div class="layui-form-item">
						<label class="layui-form-label">所属公司</label>
						<div class="layui-input-block">
							<input type="text" name="userCompanyAllTitle" lay-verify="required" autocomplete="off" placeholder="请输入所属公司" class="layui-input w30">
						</div>
					</div>-->
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="userPwd" lay-verify="required" autocomplete="new-password" placeholder="请输入密码" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮箱</label>
						<div class="layui-input-block">
							<input type="text" name="userEmail" lay-verify="email" autocomplete="off" placeholder="请输入邮箱" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">手机号</label>
						<div class="layui-input-block">
							<input type="text" name="linkmanPhone" lay-verify="required|phone" autocomplete="off" placeholder="请输入手机号" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<!--<div class="layui-inline">-->
						<label class="layui-form-label">角色</label>
						<div class="layui-input-block">
							<select name="roleIds" id="roleIds" lay-verify="required" lay-search="">
							</select>
						</div>
						<!--</div>-->
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<input type="radio" name="userStatus" value="0" title="正常" checked="">
							<input type="radio" name="userStatus" value="1" title="禁用">
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-input-block">
							<div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			layui.use(['form', 'layedit', 'upload'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					upload = layui.upload;

				//初始化角色下拉框
				$.ajax({
					url: baseUrl + "/role/getList?pageNo=1",
					type: "GET",
					success: function(data) {
						if(data.code == 200) {
							console.log(data.list);
							var datas = data.list;
							$("#roleIds").empty(); //清空下拉框
							$("#roleIds").append("<option value=''>请选择</option>");
							for(var i = 0; i < datas.length; i++) {
								var item = datas[i];
								console.log(item.id + "---" + item.roleName);
								$("#roleIds").append("<option value=" + item.id + ">" + item.roleName + "</option>");
							}
							layui.form.render('select'); //重新渲染select
						} else {
							layer.msg("角色加载失败", {
								icon: 5
							});
						}
					}
				});

				//监听提交
				form.on('submit(submitFilter)', function(data) {
					var user = JSON.parse(window.sessionStorage.getItem('user'));
					user.userCompanyAllTitle = !user.msg.userCompanyAllTitle ? "" : user.msg.userCompanyAllTitle;
					user.userCompany = !user.msg.userCompany ? "":user.msg.userCompany;
					ajaxPost({
						url: 'user/add',
						data: {
							userType: 3, //用户类型 0admin甲方 1燃气公司账号 2下游账号 3普通用户
							userAccount: data.field.userAccount, //用户名
							userCompany: user.userCompany, //所属公司简称
							userCompanyAllTitle: user.userCompanyAllTitle, //所属公司全称
							userPwd: data.field.userPwd, //密码
							userEmail: data.field.userEmail, //邮箱
							linkmanPhone: data.field.linkmanPhone, //手机号
							roleIds: data.field.roleIds, //角色
							userStatus: data.field.userStatus, //状态
						},
						successFull: function(res) {
							console.log(res)
							layer.msg('添加成功', {
								icon: 6
							});
							window.location.href = "./userList.html?pos=5&childPos=2";
						},
						errCallBack: function(res) {
							layer.msg(res.msg, {
								icon: 6
							});
						}
					})
				});

			});
		</script>
	</body>

</html>